package org.wak.scene
{
	import org.wak.baseoneonline.flash.geom.IntPoint;

	/**
	 * XML Definition of an SceneItem  
	 * 
	 */
	public class XMLItemDefinition implements ISceneItemDefinition
	{
		
		// the id of this item.
		private var mItemId:String = "" ;
		
		// Description of this item
		private var mName:String = "" ;
		
		// Description of this item
		private var mDescription:String = "" ;
		
		// Point where the player will walk to interact.
		private var mInteractionPoint:IntPoint = null ;
		
		// anim behaviour after walk to interaction point
		private var mInteractionPointBehaviour:String = ""
		
		// Point where the item will be placed in the Scene.
		private var mStartingPoint:IntPoint = null ;
		
		// The graphic or anim id to show on the Scene.
		//private var mItemDisplayId:String = "" ;
		
		// Horizontal line to draw this item back or front.
		private var mBaseline:int = 0;
		
		// visibility of the item
		private var mVisible:Boolean = true ;
		
		private var mEnabled:Boolean = true ;
		
		private var mUnitaryUse:Boolean = true ;
		
		// the default action for this object.
		private var mDefaultAction:String = "" ;
		
		// Array of views of this item.
		private var mItemViews:Array = null ;
		
		/**
		 * constructor 
		 * @param pXMLDef xml input of an scene item.
		 * 
		 */		
		public function XMLItemDefinition(pXMLDef:XML)
		{
			mItemId = pXMLDef.@id ;
			mDescription = pXMLDef.Description ;
			//mItemDisplayId = pXMLDef.DisplayObject ;
			mItemViews = new Array();
			for each( var view:XML in pXMLDef.Views.DisplayObject )
			{
				trace(view.toXMLString())
				mItemViews.push({state: String(view.@state), res: String(view[0]) });
			}
			
			
			mName = pXMLDef.Name ;
			mDefaultAction = pXMLDef.DefaultAction ;
			mUnitaryUse = pXMLDef.@unitaryUse == "true" ? true : false ;
			mEnabled = pXMLDef.@enabled == "false" ? false : true ;
			
			var fIntPoint:XML = pXMLDef.InteractionPoint.IntPoint[0] ;
			mInteractionPoint = new IntPoint(fIntPoint.@x, fIntPoint.@y);
			mInteractionPointBehaviour = pXMLDef.InteractionPoint.behaviour ;
			
			var fStartPt:XML = pXMLDef.StartingPoint.IntPoint[0] ;
			mStartingPoint = new IntPoint(fStartPt.@x, fStartPt.@y);
			mBaseline = pXMLDef.Baseline == "" ? -1 : pXMLDef.Baseline  ;
			
			mVisible = pXMLDef.@visible == "true" ? true : false ;
			
		}

		/**
		 * @inheritDoc 
		 */		
		public function get itemId():String
		{
			return mItemId;
		}
		
		/**
		 * @inheritDoc 
		 */	
		public function get itemName():String
		{
			return mName;
		}
		
		/**
		 * @inheritDoc 
		 */	
		public function get description():String
		{
			return mDescription;
		}
		
		/**
		 * @inheritDoc 
		 */	
		public function get startingPoint():IntPoint
		{
			return mStartingPoint;
		}
		
		/**
		 * @inheritDoc 
		 */	
		public function get interactionPoint():IntPoint
		{
			return mInteractionPoint;
		}
		
		/**
		 * @inheritDoc 
		 */	
		public function get interactionBehaviour():String
		{
			return mInteractionPointBehaviour ;
		}
				
		/**
		 * @inheritDoc 
		 */	
		public function get baseline():int
		{
			return mBaseline;
		}
		
		/**
		 * @inheritDoc 
		 */	
		public function get visible():Boolean
		{
			return mVisible;
		}
		
		/**
		 * @inheritDoc 
		 */	
		public function get enabled():Boolean
		{
			return mEnabled;
		}
		
		/**
		 * @inheritDoc 
		 */	
		public function get unitaryUse():Boolean
		{
			return mUnitaryUse ;
		}
		
		/**
		 * @inheritDoc 
		 */	
		public function get defaultAction():String 
		{
			return mDefaultAction ;
		}
		
		/**
		 * @inheritDoc 
		 */	
		public function get viewStates():Array 
		{
			return mItemViews ;
		}
		
	}
}